package core;

import java.util.Timer;
import java.util.TimerTask;




public class MyTimer {
	
    private TimerTask tt;
	private Timer timer = new Timer();
	
	private static MyTimer instance = new MyTimer();
	public static MyTimer getInstance(){
		return instance;
	}
	
	private MyTimer() {

	}
	
	private synchronized void start(){
		if(tt==null){
			tt = new TimerTask() {
				
				@Override
				public void run() {
					Generator.generateAll(0.001);
					
				}
			};
			timer.schedule(tt, 0, 30);
		}
	}
	private synchronized void stop(){
		if(tt!=null){
			tt.cancel();
			timer.purge();
			tt = null;
		}
	}
	synchronized void changeState(){
		if(tt==null){
			start();
		}else{
			stop();
		}
	}
}
